package com.aivin.lib_login.ui;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import com.aivin.lib_base.spiders.IGetOneShareSpiderCallBack;
import com.aivin.lib_base.spiders.SpiderOneShareDataTool;
import com.aivin.lib_base.tool.WkLog;
import com.aivin.lib_login.R;
import com.aivin.lib_login.activity.PicShowActivity;
import com.aivin.lib_login.bean.OneShareInfo;
import com.alibaba.fastjson.JSON;

public class MainExpandView extends RelativeLayout {
    private Context context;
    public MainExpandView(Context context) {
        super(context);
        initView(context);
    }

    public MainExpandView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public MainExpandView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    public MainExpandView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        initView(context);
    }

    private void initView(Context context){
        this.context =context ;
        View view = LayoutInflater.from(context).inflate(R.layout.lib_login_expandview, this);
        view.findViewById(R.id.btn_oneShare).setOnClickListener(onClickListener);
        view.findViewById(R.id.go2Pics).setOnClickListener(onClickListener);

    }


    private OnClickListener onClickListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            int id= v.getId();
            if(R.id.btn_oneShare==id){
                test();
            }

            else if(R.id.go2Pics==id){
                Intent intent = new Intent(context , PicShowActivity.class) ;
                context.startActivity(intent);
            }

        }
    };


    private SpiderOneShareDataTool spiderOneShareDataTool = new SpiderOneShareDataTool();
    private void test(){
        spiderOneShareDataTool.getOneShareData("https://gitee.com/hnyer/DataShareDev/raw/master/ShareData2.md" ,iGetOneShareSpiderCallBack ,1);
    }



    private IGetOneShareSpiderCallBack iGetOneShareSpiderCallBack =
            new IGetOneShareSpiderCallBack() {
        @Override
        public void onGetData(String jsonStr ,int type) {

            if(type==1){
                OneShareInfo item = JSON.parseObject(jsonStr, OneShareInfo.class);
                WkLog.showLog("item="+item.getType());
                for(String msg : item.getData()){
                    WkLog.showLog("item="+msg);
                }
            }



        }

        @Override
        public void onStartLoad() {

        }

        @Override
        public void onError(String error) {

        }
    };

}
